﻿// -----------------------------------------------------------------------
// <copyright file="BackpackTests.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace DotNet37Signals.Client.Test.Bootstrappers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Configuration;
    using DotNet37Signals.Client.Backpack;
    using DotNet37Signals.Client.Backpack.Contracts;
    using DotNet37Signals.Client.Backpack.Models;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class BackpackTests
    {
        public void Run()
        {
            Console.WriteLine("----------------");
            Console.WriteLine(" Backpack Tests ");
            Console.WriteLine("----------------");

            this.Initialize();

            this.Pages();

            Console.WriteLine("");
        }

        public BackpackClient Client { get; set; }

        public void Initialize()
        {
            var username = ConfigurationManager.AppSettings["username.backpack"];
            var password = ConfigurationManager.AppSettings["password"];
            var company = ConfigurationManager.AppSettings["company"];
            var keepAliveEnabled = Convert.ToBoolean(ConfigurationManager.AppSettings["keepAliveEnabled"]);

            var credentials = new Credentials(username, password, company, keepAliveEnabled);
            this.Client = new BackpackClient(credentials);
        }

        public void Pages()
        {
            Console.WriteLine();
            Console.WriteLine("Pages Contract Tests");
            Console.WriteLine("********************");

            var service = this.Client.Pages;

            var pages = service.GetList();

            Console.WriteLine("Page Count: {0}", pages.Count);

            pages = service.Search("home");

            Console.WriteLine("Search Page Count: {0}", pages.Count);
        }
    }
}
